import { songListType } from "@/types/apiType";
// 处理数字过万
const formartMyriad = (val: number) => {
  let num = 0;
  num = val > 9999 ? Math.round((val / 10000) * 10) / 10 : val;
  return num + (val > 9999 ? "万" : "");
};
// 计算时间将秒转成00:00格式
const realFormatSecond = (second: number) => {
  if (isNaN(second) || second < 0) {
    return "00:00";
  }
  const hours = Math.floor(second / 3600);
  const minutes = Math.floor((second % 3600) / 60);
  const remainingSeconds = Math.floor(second % 60);
  const formattedMinutes = String(minutes).padStart(2, "0");
  const formattedSeconds = String(remainingSeconds).padStart(2, "0");
  if (hours > 0) {
    return `${hours}:${formattedMinutes}:${formattedSeconds}`;
  } else {
    return `${formattedMinutes}:${formattedSeconds}`;
  }
};
// 歌曲毫秒格式化处理 03:30
const formatSongTime = (duration = 0) => {
  duration = duration >= 0 ? duration / 1000 : 0;
  const m = (Math.floor(duration / 60) + "").padStart(2, "0");
  const s = (Math.floor(duration % 60) + "").padStart(2, "0");
  return `${m}:${s}`;
};
//格式化播放列表详情
const formatSong = (params: songListType) => {
  return {
    id: String(params.id),
    name: params.name,
    singer: params.ar,
    album: params.al,
    duration: params.dt,
  };
};
export { formartMyriad, realFormatSecond, formatSong, formatSongTime };
